<script setup lang="ts" name="SystemOperateLogDetail">
import { formatDate } from '@/utils/dateUtil'
import type { OperateLogType } from '@/api/system/operateLog'
import { DICT_TYPE } from '@/enums/dictEnums'

const { t } = useI18n() // 国际化
const visible = ref(false) // 弹窗的是否展示
const detailData = ref({} as OperateLogType) // 详情数据

/** 打开弹窗 */
const open = async (data: OperateLogType) => {
  visible.value = true
  detailData.value = data
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗
</script>

<template>
  <Dialog v-model="visible" :title="t('sys.log.operate', 'detail')" height="60vh" type="scroll" width="800px">
    <el-descriptions :column="1" border>
      <el-descriptions-item :label="t('sys.log', 'id')" min-width="120">
        {{ detailData.id }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.log.operate', 'userId')">
        {{ detailData.userId }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.log.operate', 'nickname')">
        {{ detailData.nickname }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.log.operate', 'userIp')">
        {{ detailData.userIp }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.log.operate', 'agent')">
        {{ detailData.agent }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.log.operate', 'module')">
        {{ detailData.module }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.log.operate', 'type')">
        <dict-tag :type="DICT_TYPE.INFRA_OPERATE_TYPE" :value="detailData.type" />
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.log.operate', 'content')">
        {{ detailData.content }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.log.operate', 'extra')">
        {{ detailData.extra }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.log.operate', 'requestUrl')">
        <el-tag>{{ detailData.requestMethod }}</el-tag>
        {{ detailData.requestUrl }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.log.operate', 'createTime')">
        {{ formatDate(detailData.create_time!) }}
      </el-descriptions-item>
    </el-descriptions>
  </Dialog>
</template>

<style scoped lang="scss"></style>
